package com.res.service.impl;

import com.res.entity.Readroom;
import com.res.repository.ReadRoomRepository;
import com.res.service.ReadRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReadRoomServiceImpl implements ReadRoomService {
    @Autowired
    private ReadRoomRepository readRoomRepository;
    @Override
    public List<Readroom> findAllReadRoom() {
        return readRoomRepository.findAll();
    }

    @Override
    public long countReadRoom() {
        return readRoomRepository.count();
    }

    @Override
    public Integer addReadRomm(Readroom readroom) {
        try{
            readRoomRepository.saveAndFlush(readroom);
            return 1;
        }catch (Exception e){
            e.printStackTrace();
            return  0;
        }
    }

   /* @Override
    public Integer updateReadRoom(Readroom readroom) {
        return null;
    }*/

    @Override
    public Integer deleteReadRoom(Integer rid) {
        try {
            readRoomRepository.deleteById(rid);
            return  1;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
}
